#!/bin/bash

set -e

: ${GEM_HOME:?must be set}

RUBY_MAJOR="2.0"
RUBY_VERSION="2.0.0-p594"

mkdir -p /usr/src/ruby
curl -SL "http://cache.ruby-lang.org/pub/ruby/$RUBY_MAJOR/ruby-$RUBY_VERSION.tar.bz2" \
  | tar -xjC /usr/src/ruby --strip-components=1
cd /usr/src/ruby
autoconf
./configure --disable-install-doc
make -j"$(nproc)"
yum remove -y ruby
make install
rm -r /usr/src/ruby && cd
echo 'gem: --no-rdoc --no-ri' >> "$HOME/.gemrc"
mkdir -p "$GEM_HOME"
gem install bundler
bundle config --global path "$GEM_HOME"
bundle config --global bin "$GEM_HOME/bin"
